<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<link rel="shortcut icon" href="../../share/img/logo.png">
		<link rel="stylesheet" href="../../share/css/main.css">
		<script src="../../share/js/jquery-1.11.3.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../share/js/util.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body class="p-10">
		<h1>集合</h1>
		<div class="row">
			<div class="col-1">
				<section>
					<h3>Set</h3>
					<button id="btn1">去重</button>
					<button id="btn2">遍历</button>
					<button id="btn3">交并差</button>
				</section>
				<section>
					<h3>Map</h3>
				</section>
			</div>
			<div class="col-1">
			</div>
			<div class="col-1">
				<ul id="log" class="d-list mt-10"></ul>
			</div>
		</div>
		<script>
			{
				$("#btn1").click(test1);
				$("#btn2").click(test2);
				$("#btn3").click(test3);

				function test1() {
					let a1 = [1, 2, 3, 3, 2, 1, 4, 6, 3];
					let s1 = new Set(a1);
					util.clearLog().appendLog("原数组:" + a1.join(","));
					util.appendLog("去重后:" + [...s1].join(","));
				}

				function test2() {
					let s1 = new Set();
					s1.add("apple").add("pear").add("orange").add("banana");
					for (let x of s1) {
						util.appendLog(x);
					}
				}

				function test3() {
					let s1 = new Set([1, 2, 3, 4]);
					let s2 = new Set([1, 2, 5, 6]);
					util.clearLog().appendLog("s1:" + [...s1].join(",")).appendLog(("s2:" + [...s2].join(",")));
					let s3 = new Set([...s1, ...s2]);
					util.appendLog("并集:" + [...s3].join(","));
					let s4 = new Set([...s1].filter(x => s2.has(x)));
					util.appendLog("交集:" + [...s4].join(","));
					let s5 = new Set([...s1].filter(x => !s2.has(x)));
					util.appendLog("差集:" + [...s5].join(","));
				}

			}
		</script>
	</body>
</html>
